package symType;

import dbTools.DBTools;
import sym.SymMessageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * Servlet implementation class SymUpdateInnerServlet
 */
@WebServlet("/SymUpdateInnerServlet")
public class SymUpdateInnerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SymUpdateInnerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=GBK");
		request.setCharacterEncoding("GBK");
		response.setCharacterEncoding("GBK");
		String sym =new String(request.getParameter("sym").getBytes("ISO-8859-1"),"GBK");
		String[] symStr=sym.split(",");
		String symId=symStr[0];
		String typeId=symStr[1];
		String sqlu="UPDATE symInfo SET TypeId=NULL WHERE symId="+symId+";";
		DBTools db=new DBTools();
		db.open();
		db.update(sqlu);
		String sql1="SELECT * FROM symInfo WHERE typeId="+typeId+";";
		SymMessageBean sc=null;
		ArrayList al1=new ArrayList();
		ResultSet rs1=db.select(sql1);
		try {
			while (rs1.next()) {
				sc=new SymMessageBean(rs1.getInt(1),rs1.getString(2),rs1.getInt(3));
				al1.add(sc);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String sql2="SELECT * FROM symInfo";
		ArrayList al2=new ArrayList();
		ResultSet rs2=db.select(sql2);
		try {
			while (rs2.next()) {
				sc=new SymMessageBean(rs2.getInt(1),rs2.getString(2),rs2.getInt(3));
				al2.add(sc);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String sql="SELECT * FROM symTypeInfo WHERE symTypeId="+typeId+";";
		SymClassifyBean st=null;
		ArrayList al=new ArrayList();
		ResultSet rs=db.select(sql);
		try {
			while (rs.next()) {
				st=new SymClassifyBean(rs.getInt(1),rs.getString(2));
				al.add(st);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("st", st);
		request.setAttribute("symTypeId", typeId);
		request.setAttribute("al1", al1);
		request.setAttribute("al2", al2);
		db.close();
		request.getRequestDispatcher("/symInnerMessage.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
